<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Demo01</title>
</head>

<body>
  <!-- 封装数据 -->
  <script>
    var myObj = (function () {
      var __name = 'Ling'
      return {
        getName: function () {
          return __name
        },
        setName: function (name) {
          __name = name
          return this
        }
      }
    })();

    console.log(myObj.__name)
    console.log(myObj.setName('Ling---').getName())
  </script>
</body>

</html>